# coding=utf-8
__author__ = 'wenke1'

import os
'''
3-5.写一个函数，返回指定目录下含有指定字符的所有文件
'''
def isIncludeStr(filename,targetStr):
    '''
    :param filename: absolute file path
    :param targetStr: str
    :return:0 means not include the filterStr
    '''
    fp=open(filename)
    for line in fp:
        if targetStr in line:
            return 1
    fp.close()
    return 0

def findTargetFile(targetDir,targetStr):
    '''
    :param targetDir:  指定的目录（路径）
    :param targetStr:  需要查找的文件里包含字符 string
    :return:  null
    '''

    if os.path.exists(targetDir):
        targetFile=[]
        for i in os.walk(targetDir):
            for j in i[2]:
                absfilepath=os.path.join(i[0],j)
                if isIncludeStr(absfilepath,targetStr):
                    targetFile.append(absfilepath)
        print targetFile
    else:
        print "dir is not exist"

targetDir=r'D:\project\workshop\project_xmlrpc'
filterString='sstest'
findTargetFile(targetDir,filterString)